<template>
    <div>
        <p>支付成功，正在跳转到首页，请稍后 ……</p>
        <p>订单号: {{ outTradeNo }}</p>
        <p>支付金额: {{ totalAmount }}</p>

    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { chooseTable } from '@/api/dashed';
import { wait } from '@/api/pay';
const router = useRouter()
const route = useRoute()
const outTradeNo = ref('')
const totalAmount = ref('')
const res = ref({})
onMounted(() => {
    const params = new URLSearchParams(route.query)
    outTradeNo.value = params.get('out_trade_no') || '未知'
    totalAmount.value = params.get('total_amount') || '未知'
    params.forEach((value, key) => {
        res.value[key] = value
    })
    subPaySuccess()
})
//返回首页
const goHome = () => {
    setTimeout(() => {
        router.push('/')
    }, 3000);
}
/**
 * @description: 初始化球桌状态
 * @return {*}
 */
const iniTable = async () => {
    const res = await chooseTable({ id: route.query.out_trade_no.charAt(0), status: 0 })
    if (res.message === 'success') {
        goHome()
    }
}

const subPaySuccess = async () => {
    const payRes = await wait(res.value)
    console.log(payRes)
    if (payRes.data.payStatus == 2) {
        goHome()
    } else {
        iniTable()
    }
}
</script>

<style scoped>
/* 添加一些样式以确保页面看起来不错 */
</style>